<?php
require ('../common.inc.php');

if($_POST['act'] == 'alogin'){
	$auname = checkstr(trim($_POST['auname']));
	$phone = checkstr(trim($_POST['phone']));
	//$sjcode = checkstr(trim($_POST['sjcode']));
	$pwd = checkstr($_POST['apwd']);
	//$ga=checkstr(trim($_POST['uc_ga']));
	if(empty($auname)) msg_b("请输入用户名");
	if(empty($pwd)) msg_b("请先输入密码");
	// if(empty($sjcode)) msg_b("请先输入手机验证码");

	//if(empty($ga)) msg_b("请输入双重验证码");
	$valicode = checkstr($_POST['valicode']);
	if($valicode != $_SESSION['valicode']){
		msg_b("验证码错误！");
	}
	$adminra=$member->getua($auname);

	if(empty($adminra)) msg_b("您不是管理员");
	if($adminra["status"]) msg_b("您已经被禁止登录");
	/*
	$param['pt'] = $adminra['password'];
	$param['in'] = $pwd.SITEENCRYPT;
	$param['getin'] = getpwd($pwd);	
	print_r($param);die;
	*/
	if($adminra['password']!=getpwd($pwd))  msg_b("您输入的密码不正确");
	$r=$member->getuserinfo($auname,true);
	//print_r($r);die;
	if($r["is_freezed"]&&$r["id"]!=1){
		header("Location:index.php");
	}
/* 	$ga_n = new GoogleAuthenticator();
	$arr = explode('|', $r['ga']);
	$secret = $arr[0];
	$aa = $ga_n->verifyCode($secret, $ga, 1);
	if (!$aa){
		msg_b('双重身份验证码错误！');
	} */
	$_SESSION["houname"]=$_username=$r['uname'];
	$_SESSION["houid"]=$_userid=$_SESSION['userid']=$r['id'];
	/**
    if(($phone!='13922312284'  && $phone!='15764251917')||$sjcode!=$_SESSION['admin']){

    	 // msg_b("手机验证吗不正确");
    }*/
	$loginip=getrealip();
	$db->sitedbexec("insert into ld_login_log(uname,ll_time,ll_status,loginip) values('".$r['uname']."',".time().",1,'$loginip')");
	$db->sitedbexec("update ld_user set last_login_time=".time().",loginip='".$loginip."' where uname='$_username'");
	$_SESSION["savetime"]=time();
	unset ($_SESSION['admin']);
	header("Location:./main.php?lsaction=index");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
	<meta content="width=device-width, initial-scale=0.4, maximum-scale=1.0, user-scalable=1" name="viewport">
	<meta content="yes" name="apple-mobile-web-app-capable">
	<meta content="black" name="apple-mobile-web-app-status-bar-style">
	<meta content="telephone=no" name="format-detection">
    <meta name="renderer" content="webkit">
    <title>管理后台登录</title>
	<link rel="stylesheet" type="text/css" href="../theme/css/main.css" />
    <link href="../theme/css/style.css" rel="stylesheet" type="text/css" />
    <link href="../theme/css/plugs.css" rel="stylesheet" type="text/css" />
	<link href="../theme/css/H-ui.reset.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../theme/js/jquery.min.js"></script>
	<!--[if lt IE 9]>
	<script type="text/javascript" src="../theme/js/html5.js"></script>
    <![endif]-->
</head>
<style type="text/css">
	.baitab td{padding-bottom: 10px;}
</style>
<body style="position: relative;">
<div class="admin_login">
	<div class="altitle" style="text-align: center;font-size: 24px;color: #fff;font-weight: 900;margin-top: 110px;margin-bottom: 40px;">后台登录</div>
	<form name="theform" action="wologin.php?link=<?php echo $_GET['link']; ?>" method="post" onsubmit="return chksubmit()">
		<input type="hidden" name="act" value="alogin" />
		<table width="100%" border="0" cellpadding="0" cellspacing="0"  style="margin-top:20px;width:800px;background:#fff;border-radius: 5px;"  class="baitab" align="center">
			<tbody>
				<tr>
					<td style="height: 30px;"></td>
					<td></td>
				</tr>
				<tr>
					<td width="40%" valign="top" align="right">用户名：</td>
					<td valign="top"><input type="text" name="auname" id="auname" class="reginput" maxlength="30"></td>
				</tr>
				<tr>
					<td width="40%" valign="top" align="right">后台登录密码：</td>
					<td valign="top"><input type="password" name="apwd" id="apwd" class="reginput" maxlength="30"></td>
				</tr>
				<tr>
					<td width="40%" valign="top" align="right">验证码：</td>
					<td valign="top"><input name="valicode" id="valicode" class="reginput" type="text" size="6" maxlength="6" /> <img src="checkcode.php" id="valicodeimg" alt="看不清验证码?点击刷新!" onClick="changeCode()" style="width:100px;height:30px;font-size: 20px;color: #fff;" /></td>
				</tr>
                <!--
				<tr>
				    <td width="40%" valign="top" align="right">手机号：</td>
				    <td valign="top"><input name="phone" id="phone" class="reginput" type="text" />
				    <input type="button" value="发送验证码" id="btnSendCode" onclick="sendSms()" class="btn btn-success" />
				</td>
				<tr>
				<tr>
				    <td width="40%" valign="top" align="right">手机验证码：</td>
				    <td valign="top"><input name="sjcode" id="sjcode" class="reginput" type="text" />
				</td>
				<tr>
					<td width="40%" valign="top" align="right">双重验证码：</td>
				    <td valign="top"><input name="uc_ga" id="uc_ga" class="reginput" type="text" />
				</tr>-->
				<tr>
					<td width="40%" valign="top" align="right" style="height:50px;line-height:50px"></td>
					<td valign="top" style="height:50px;line-height:50px"><input type="submit" value="登录" class="btn btn-success" style="width: 150px;height: 40px;border-radius: 5px;background: #2f89dc;font-size: 18px;color: #fff;border:none;"></td>
				</tr>
			</tbody>
		</table>
	</form>
</div>
<script type="text/javascript" src="/public/home/js/layer/layer.js"></script>
<script type="text/javascript">
function chksubmit(){
	var auname = $.trim($("#auname").val());
	if($.trim(auname) == ""){
		alert("请输入用户名！");
		return false;
	}
	var result = auname.match(/^[a-zA-Z0-9][a-zA-Z0-9_]{3,14}$/);
	if (result == null) {
        alert("用户名格式不正确！");
		return false;
    }
	var apwd = $.trim($("#apwd").val());
	if($.trim(apwd) == ""){
		alert("请输入密码！");
		return false;
	}
	var valicode = $.trim($("#valicode").val());
	if($.trim(valicode) == ""){
		alert("请输入验证码！");
		return false;
	}
	return true;
}
function changeCode(){
	document.getElementById('valicodeimg').src ="checkcode.php?r=" + Math.random();
}
window.onload=function(){
	changeCode();
}
 var InterValObj; //timer变量，控制时间
    var count = 60; //间隔函数，1秒执行
    var curCount;//当前剩余秒数
    function sendSms(){
        $.ajaxSetup({
            async: false
		});

        var phone = $("#phone").val();

         //两者格式都争取情况下可发送手机验证码
    	 curCount = count;
  	　　//设置button效果，开始计时
  	     $("#btnSendCode").attr("disabled", "true");
  	     $("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
  	     InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器，1秒执行一次

		 $.ajax({
			type: "get",
			dataType: "json",
			url: "/plus/sendadmin.php?phone="+phone,
			success: function(data){
				layer.alert(data.res);
			},
			error: function(){

			},
			cache: false,
			async: false
		 });
    }
    //timer处理函数
    function SetRemainTime() {
		if(curCount == 0){
          window.clearInterval(InterValObj);//停止计时器
          $("#btnSendCode").removeAttr("disabled");//启用按钮
          $("#btnSendCode").val("重新发送验证码");
		}else{
           curCount--;
           $("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
		}
    }
</script>
<div class="bottom"><?php echo $GLOBALARR['sytitle'];  ?></div>
</body>
</html>